import Vue from 'vue'
import VueRouter from 'vue-router'
import ScenicExhibition from '../views/scenic/ScenicExhibition.vue'
import home from '../views/home.vue'
import ScenicRegionView from '../views/scenic/ScenicRegionView.vue'
import ScenicspotDetailsView from '../views/scenic/ScenicspotDetailsView.vue'
import Login from '../views/login/Login.vue'
import MyHomePage from '../views/MyHomePage/MyHomePage.vue'
import Leaflet from '../views/leaflet/Leaflet.vue'
import TourNote from '../views/scenic/TourNote.vue'
import OrderManager from '../views/order/OrderManager.vue'
import card from '../views/card/card.vue'
import Cardintroduce from '../views/card/Cardintroduce.vue'
import BuyCard from '../views/card/BuyCard.vue'
import Register from '../views/register/Register.vue'
import TravelDitails from '../views/scenic/TravelDitails.vue'
import MyMember from '../views/card/MyMember.vue'
import PayCards from '../views/card/PayCards.vue'
import CheckCardDetail from '../views/card/CheckCardDetail.vue'
import MyCollection from '../views/collection/MyCollection.vue'
import Chat from '../views/chat/Chat.vue'
import PurchaseSuccess from '../views/scenic/PurchaseSuccess.vue'
import ScenicPay from '../views/scenic/ScenicPay.vue'
import Alipay from '../views/alipay/Alipay.vue'
import UserEdit from '../views/user/UserEdit.vue'
import UserRealBinds from '../views/user/UserRealBinds.vue'
import PersonalHomepage from '../views/personal/PersonalHomepage.vue'
import OrderDetail from '../views/order/OrderDetail.vue'
import { Message } from 'element-ui'

Vue.prototype.$message = Message;

Vue.use(VueRouter)


//解决重复点击导航时，控制台出现报错
//Uncaught (in promise) NavigationDuplicated: Avoided redundant navigation to current location
const VueRouterPush = VueRouter.prototype.push
VueRouter.prototype.push = function push (to) {
  return VueRouterPush.call(this, to).catch(err => err)
}

const routes = [
	{
		path: '/',
		name: 'home',
		component: home,
		children: [
			{
				path: '/',
				name: 'ScenicExhibition',
				component: ScenicExhibition
			},
			{
				path: '/PurchaseSuccess',
				name: 'PurchaseSuccess',
				component:PurchaseSuccess
			},
			{
				path: '/ScenicRegionView',
				name: 'ScenicRegionView',
				component:ScenicRegionView
			},
			{
				path: '/ScenicspotDetailsView',
				name: 'ScenicspotDetailsView',
				component:ScenicspotDetailsView
			},
			{
				path: '/MyHomePage',
				name: 'MyHomePage',
				component:MyHomePage
			},
			{
				path: '/OrderManager',
				name: 'OrderManager',
				component:OrderManager
			},
			{
				path: '/Leaflet',
				name: 'Leaflet',
				component:Leaflet
			},
			{
				path: '/TourNote',
				name: 'TourNote',
				component:TourNote
			},
			{
				path: '/TravelDitails',
				name: 'TravelDitails',
				component:TravelDitails
			},
			{
				path: '/card',
				name: 'card',
				component: card
			},
			{
				path: '/Cardintroduce',
				name: 'Cardintroduce',
				component: Cardintroduce
			},
			{
				path: '/BuyCard',
				name: 'BuyCard',
				component: BuyCard
			},
			{
				path: '/MyMember',
				name: 'MyMember',
				component: MyMember
			},
			{
				path: '/PayCards',
				name: 'PayCards',
				component: PayCards
			},
			{
				path: '/CheckCardDetail',
				name: 'CheckCardDetail',
				component: CheckCardDetail
			},
			{
				path: '/MyCollection',
				name: 'MyCollection',
				component: MyCollection
			},
			{
				path: '/Chat',
				name: 'Chat',
				component: Chat
			},
			{
				path: '/scenicTickets',
				name: 'scenicTickets',
				component: () => import('../views/scenic/ScenicTicketsView.vue')
			},
			{
				path: '/ScenicPay',
				name: 'ScenicPay',
				component: ScenicPay
			},
			// lzy 2022-8-23 19点06分
			{
				path: '/OrderDetail',
				name: 'OrderDetail',
				component:OrderDetail
			}
		]
	},
	{
		path: '/login',
		name: 'login',
		component: Login
	},
	{
		path: '/register',
		name: 'register',
		component: Register
	},
	{
		path: '/Alipay',
		name: 'Alipay',
		component: Alipay
	},
	
	// fys 2022-8.22 15点11分
	{
		path: '/PersonalHomepage',
		name: 'PersonalHomepage',
		component:PersonalHomepage,
		meta: { title: '个人主页' },
		children: [
			// fys 2022-8.17 16点01分
			{
				path: '/UserEdit',
				name: 'UserEdit',
				component:UserEdit,
				meta: { title: '查看个人信息' }
			},
			// lzy 2022-8.18 20点30分
			{
				path: '/UserRealBinds',
				name: 'UserRealBinds',
				component:UserRealBinds,
				meta: { title: '查看绑定实名信息' }
			},
		]
	}
]

const router = new VueRouter({
  routes
})

router.beforeEach((to, from, next) => {
	if (to.path !== '/login') {
		window.sessionStorage.setItem("toPath", to.path)
	} 
	console.log(window.sessionStorage.getItem("toPath"))
	next()
})

export default router
